﻿using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using CallCenter.Data;
using CallCenter.Data.BizUtilities;
using System.Configuration;
using System.Data;
using CallCenter.Security;
using CallCenter.Data.Models;
using CallCenter.Data.Misc;

namespace CallCenter.Web.Controllers
{
    public class CreateMenuController : BaseController
    {
        // GET: CreateMenu
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult MenuHistory()
        {
           FeaturesVM  cmpy = new FeaturesVM();
            return View(cmpy);
        }
        public JsonResult GetMenus()
        {
            var scratchPads = this.Bridge.MenuUtility.GetAll();
            return Json(scratchPads, JsonRequestBehavior.AllowGet);
        }

        public JsonResult GetMainMenu()
        {
            var scratchPads = this.Bridge.MenuUtility.GetMainMenuItems();
            return Json(scratchPads, JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public JsonResult CreateMenuSetUp(FeaturesVM model)
        {
           

            var returnMessage = this.Bridge.MenuUtility.InsertToMenu(model); ;
            if (!returnMessage.Status)
                ModelState.AddModelError("Error", returnMessage.Message);
            else {
                return Json(new AjaxSuccess { Message = "Success" }, JsonRequestBehavior.AllowGet);
            }
           

            return Json(new AjaxFailure { Errors = ModelState.SerializeErrors }, JsonRequestBehavior.DenyGet);
        }

        [HttpPost]
        public JsonResult DeleteMenu(FeaturesVM model)
        {
            //insert items into respective tables
            int id = model.id;
            this.Bridge.MenuUtility.Delete(id);
            var returnMessage = "Success";
            return Json(returnMessage, JsonRequestBehavior.AllowGet);

        }

        [HttpPost]
        public JsonResult UpdateMenu(FeaturesVM model)
        {
            var result = this.Bridge.MenuUtility.UpdateToMenu(model);
            return Json(result, JsonRequestBehavior.AllowGet);
        }



    }
}